package com.tedu.bill.demo1;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author：毕龙
 * Date: 2024/5/26 11:19
 */
public class TestFile1 {
    public static void main(String[] args) {
        //file文件操作文件
        File file = new File("day14/src/a");
        //创建文件夹
        file.mkdir();
        File file2 = new File("day14/src/a/c");
        file2.mkdir();
        File file3 = new File("day14/src/a/b/d");
        //如果文件中的一个文件目录不存在则不创建文件夹或文件
        //file3.mkdir();
        file3.mkdirs();

        Date date = new Date("2024/6/26");
        //yyyy/MM/dd
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String format = sdf.format(date);
        System.out.println(format);
        File file4 = new File("day14/src/a/"+format);
        file4.mkdirs();
        //获取文件夹的名字
        String name = file4.getName();
        System.out.println(name);

        //boolean delete = file4.delete();

        File[] length = file4.listFiles();
        System.out.println(length.length);
        //生命两个变量
        int fileCount = 0;
        int directoryCount = 0;
        for (File file1 : length) {
            if(file1.isFile()){
                fileCount ++;
            }else{
                directoryCount ++;
            }
        }
        System.out.println("文件夹："+directoryCount);
        System.out.println("文件："+fileCount);


    }
}
